<template>
	<view>
		<view class="tip">给自己起个喜欢的名称</view>
		<view class="input-wrap">
			<input type="text" v-model="nickName" placeholder="给自己起个喜欢的名称" />
			<uni-icons @click="handleClear" type="close" size="20" color="#999"></uni-icons>
		</view>
		
		<view class="common-btn" @click="handleSave">保存</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nickName: '',
			};
		},
		onLoad(opt) {
			this.getUserInfo()
			if(opt.type && opt.type == 2037){
				uni.showToast({
					title: '请修改昵称',
					icon: 'none'
				})
			}
		},
		methods: {
			handleClear() {
				this.nickName = ''
			},
			handleSave() {
				if (!this.nickName.trim()) { return uni.showToast({title: '名称不能为空喔',icon: 'none'}) }
				this.$http.get(this.$api.EditNickName, {nickname:this.nickName}).then(res => {
					if (res.code === 200) {
						uni.navigateBack({delta: 1});
					}
				})
				
			},
			getUserInfo() {
				this.$http.get(this.$api.getUserInfo).then(res => {
					if (res.code === 200) {
						this.nickName = res.data.nickname
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.tip {
	font-size: 24rpx;
	height: 75rpx;
	line-height: 75rpx;
	padding: 0 30rpx;
}
.input-wrap {
	height: 100rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 30rpx;
	background-color: #fff;
	font-size: 28rpx;
}
.common-btn {
	width: 520rpx;
	box-shadow: none;
	margin-top: 100rpx;
}
</style>
